//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: '欢迎使用随手记',
    abcCtxt: '',
    userInfo: {}
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    console.log('onLoad');
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        var speed = res.speed
        var accuracy = res.accuracy
        console.log('latitude=' + latitude + 'longitude=' + longitude + 'speed=' + speed + 'accuracy=' + accuracy);
      }
    });

    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }, 
  formSubmit: function(e){

    console.log(e.detail.value.ctxt);
    var ctxtVal = e.detail.value.ctxt;
    if(!ctxtVal){
      wx.showToast({
        title: '内容不能为空哦',
        image: 'close.png',
        duration: 2000
      });
      return;
    }

    wx.showToast({
      title: '正在处理',
      icon: 'loading',
      duration: 2000
    });
    var thisT = this;
    wx.request({
      url: 'https://zcjb.com.cn/cms/check.htm', //仅为示例，并非真实的接口地址
      data: {
        ctxt: ctxtVal
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data);
        thisT.setData({
          abcCtxt: ''
        });
        wx.showToast({
          title: res.data,
          icon: 'success',
          duration: 2000
        });
      }
    })
  }
})
